﻿package view.component
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import pluginfw.nio.*;

    public class TemptationCell extends Sprite
    {
        private var mainSp:Sprite;
        private var txt:Label;
        private var isShow:Boolean = false;
        public var data:Object;
        public var registerPoi:Point;
        public var _initAnimate:Handler;
        public var _IconMc:XMLMovieClip;

        public function TemptationCell()
        {
            this.mainSp = new Sprite();
            this.registerPoi = new Point();
            this.addChild(this.mainSp);
            return;
        }// end function

        public function show(param1:Object, param2:Handler = null) : void
        {
            this.data = param1;
            this._initAnimate = param2;
            if (this.isShow)
            {
                this.dispose();
            }
            this.initEvent();
            XMLMcManager.instance.MainuiMc(this.data.icon, this.onComplete);
            return;
        }// end function

        private function onComplete(param1:XMLMovieClip) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Handler = null;
            this._IconMc = param1;
            this._IconMc.y = 0;
            this.mainSp.addChild(this._IconMc);
            this.isShow = true;
            if (this.data.icon == "tzdp")
            {
                this._IconMc.interval = 160;
            }
            else
            {
                this._IconMc.interval = MornConfig.MOVIE_INTERVAL;
            }
            if (this.data.icon == "cyfs" || this.data.icon == "xmfs" || this.data.icon == "jxfs")
            {
                this._IconMc.y = -30;
            }
            else if (this.data.icon == "zhbh")
            {
                this._IconMc.y = -10;
            }
            else if (this.data.icon == "hbpx")
            {
                this._IconMc.y = -15;
            }
            else
            {
                this._IconMc.y = 0;
            }
            this.txt = new Label();
            this.txt.stroke = "0x0";
            if (this.data.level)
            {
                _loc_2 = UserData.getUserData("level");
                this.changeState(_loc_2 >= this.data.level);
            }
            this.checkFashenState();
            this.txt.width = 160;
            this.txt.size = 14;
            this.txt.align = "center";
            this.txt.y = this._IconMc.height - 15;
            if (this.data.icon == "szbj" || this.data.icon == "tmsj")
            {
                this.txt.y = this.txt.y - 25;
            }
            else if (this.data.icon == "zhbh")
            {
                this.txt.y = this.txt.y + 5;
            }
            else if (this.data.icon == "cyfs" || this.data.icon == "hbpx" || this.data.icon == "xmfs" || this.data.icon == "jxfs")
            {
                this.txt.y = this.txt.y + -15;
            }
            else if (this.data.icon == "fspf")
            {
                this.txt.y = this.txt.y + 5;
            }
            else if (this.data.icon == "tchd")
            {
                this.txt.y = this.txt.y + 10;
            }
            else if (this.data.icon == "jxfs")
            {
                this.txt.y = this.txt.y + 7;
            }
            else if (this.data.icon == "tscp")
            {
                this.txt.y = this.txt.y - 20;
            }
            this.mainSp.addChild(this.txt);
            this.registerPoi.x = this.mainSp.width >> 1;
            this.registerPoi.y = this.mainSp.height >> 1;
            this.mainSp.x = -this.registerPoi.x;
            this.mainSp.y = -this.registerPoi.y;
            this.x = this.registerPoi.x;
            this.y = this.registerPoi.y;
            if (this._initAnimate)
            {
                _loc_3 = this._initAnimate;
                this._initAnimate = null;
                _loc_3.execute();
            }
            return;
        }// end function

        public function dispose() : void
        {
            XMLMcManager.instance.removeMainMc(this._IconMc);
            if (this.txt)
            {
                this.txt.parent.removeChild(this.txt);
                this.txt = null;
            }
            this.removeEvent();
            this.isShow = false;
            return;
        }// end function

        public function initEvent() : void
        {
            this.addEventListener(MouseEvent.CLICK, this.doMouse);
            this.addEventListener(MouseEvent.ROLL_OVER, this.doMouse);
            this.addEventListener(MouseEvent.ROLL_OUT, this.doMouse);
            return;
        }// end function

        public function removeEvent() : void
        {
            this.removeEventListener(MouseEvent.CLICK, this.doMouse);
            this.removeEventListener(MouseEvent.ROLL_OVER, this.doMouse);
            this.removeEventListener(MouseEvent.ROLL_OUT, this.doMouse);
            return;
        }// end function

        protected function doMouse(event:MouseEvent) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Object = null;
            switch(event.type)
            {
                case MouseEvent.ROLL_OVER:
                {
                    if (this.data.link)
                    {
                        return;
                    }
                    _loc_2 = ConfigDictionary.data.item;
                    _loc_3 = _loc_2[this.data.itemid];
                    ModelProxy.change("tips", "arm", {data:_loc_3, p:new Point(GlobalLayer.instance.flashStage.mouseX, GlobalLayer.instance.flashStage.mouseY)});
                    break;
                }
                case MouseEvent.ROLL_OUT:
                {
                    ModelProxy.change("tips", "state", "close");
                    break;
                }
                case MouseEvent.CLICK:
                {
                    if (this.data.link)
                    {
                        ModelProxy.change("plugin", "open", {target:this.data.link, point:UIGlobel.pointsDic["fashen"]});
                        return;
                    }
                    this.doClick();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function changeState(param1:Boolean) : void
        {
            if (this.txt == null)
            {
                return;
            }
            if (param1)
            {
                this.txt.color = MColor.New69;
                this.txt.text = "可领取";
            }
            else
            {
                this.txt.text = this.data.title;
                this.txt.color = MColor.New58;
            }
            return;
        }// end function

        public function checkFashenState() : void
        {
            var _loc_1:int = 0;
            if (this.data.day)
            {
                if (this.data.day > 1)
                {
                    _loc_1 = ModelProxy.getValue("data", "logindaycount");
                    if (_loc_1 >= this.data.day)
                    {
                        this.txt.color = MColor.New69;
                        this.txt.text = "可激活";
                    }
                    else
                    {
                        this.txt.text = this.data.title;
                        this.txt.color = MColor.New58;
                    }
                }
            }
            return;
        }// end function

        private function doClick() : void
        {
            var _loc_2:Output = null;
            ModelProxy.change("tips", "state", "close");
            var _loc_1:* = UserData.getUserData("level");
            if (_loc_1 >= this.data.level)
            {
                _loc_2 = new Output();
                _loc_2.writeVarInt(this.data.itemid, false);
                PluginManager.instance.sendToBufferServer("activity", CMDActivity._32TOGETTEMPTATION, _loc_2);
            }
            else
            {
                WarningManager.show(38, [this.data.level]);
            }
            return;
        }// end function

        public function changeTxtColor(param1:int) : void
        {
            if (this.txt)
            {
                this.txt.color = param1;
            }
            return;
        }// end function

    }
}
